package com.cl.master.mapper;

import com.cl.master.domain.Note;
import com.cl.master.domain.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author xc
 * @Date 2023/5/18 17:57
 * @Version 1.0
 */
@Mapper
@Component//idea高版本不会警告错误，可省略
public interface UserMapper {
    // User(id=0, username=1, realName=晓辰, address=zdcz, phone=15589677889)

    @Insert("INSERT INTO user (id, username, realName, address, phone, emergencyPhone, emergencyContact) VALUES (#{id}, #{username}, #{realName}, #{address}, #{phone}, #{emergencyPhone}, #{emergencyContact})")
    void saveUser(User user);

    // @Select("SELECT * FROM user WHERE username = #{loginAdmin} LIMIT 1")
    // @Select("SELECT * FROM user WHERE id = (SELECT MAX(id) FROM user WHERE username = #{loginAdmin}")
    @Select("SELECT * FROM user WHERE username = #{loginAdmin} ORDER BY id DESC LIMIT 1")
    Map<String, Object> getForm(String loginAdmin);
}
